import { exec } from "node:child_process";

export const checkQQMusicInstalled = (): Promise<boolean> => {
  return new Promise((resolve) => {
    // 定义所有可能的注册表位置
    const registryPath =
      "HKLM\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall";

    const searchTerms = ["QQ音乐", "QQMusic"];
    let found = false;
    exec(
      `reg query "${registryPath}" /s /f "QQ音乐"`,
      (err: any, stdout: string) => {
        if (
          stdout &&
          (stdout.includes("QQ音乐") || stdout.includes("QQMusic"))
        ) {
          found = true;
          console.log(`找到匹配项: QQ音乐 在 ${registryPath}`);
          return resolve(found);
        }

        exec(
          `reg query "${registryPath}" /s /f "QQMusic"`,
          (err: any, stdout: string) => {
            if (
              stdout &&
              (stdout.includes("QQ音乐") || stdout.includes("QQMusic"))
            ) {
              found = true;
              console.log(`找到匹配项: QQMusic 在 ${registryPath}`);
              return resolve(found);
            }
            resolve(found);
          }
        );
      }
    );
  });
};

checkQQMusicInstalled().then((res) => {
  console.log("是否安装：", res);
});
